package com.yanqu.road.server.logic.activity.condition.zhenhuan;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.zhenhuan.secondProcess.UserZhenHuanSecondProcessData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.zhenhuan.ZhenHuanSecondProcessModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;

import java.math.BigInteger;

public class ZhenHuanSecondProcessRankCondition extends BaseNewRankActivityCondition {
    public ZhenHuanSecondProcessRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        UserZhenHuanSecondProcessData userData = player.getModule(ZhenHuanSecondProcessModule.class).getUserData();
        if (userData == null) {
            return;
        }
        if (userData.getPrestigeDegree() > 0 || userData.getLoveDegree() > 0) {
            BigInteger oldValue = getValue();
            String oldParam = getParam();

            setValue(BigInteger.valueOf(userData.getLevel()));
            setParam(String.valueOf(userData.getPrestigeDegree()));

            if (oldValue.compareTo(getValue()) != 0 || !oldParam.equals(getParam())) {
                rankChange();
            }
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ZhenHuanSecondProcessRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ZhenHuanSecondProcessRank.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo){
        return true;
    }
}
